package com.xxwu.aspect.component;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component

/**
 * 实现AOP
 * 1 定义切点表达式
 * 2 自定义注解
 */
public class AspectDemo {
    @Around("execution(* com.xxwu.aspect.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        log.info("切点方法执行前执行");
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info("切点方法执行后执行");
        log.info(pjp.getSignature()+ "：执行耗时：" + (end - start) + "ms");
        return result;
    }
}
